﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using com.dz.ct.common;
using com.dz.ct.business;
using com.dz.ct.components;

namespace com.dz.ct.ui
{
    public partial class FrmSite : Form
    {

        /// <summary>
        /// 修改的数据记录
        /// </summary>
        public DataRow m_data_row = null;

        public FrmSite()
        {
            InitializeComponent();
        }

        /// <summary>
        /// 确定操作
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void btnSure_Click(object sender, EventArgs e)
        {
            SmallSiteInfo t_book_site = new SmallSiteInfo();
            t_book_site.BookListReg = txt_book_list_reg.Text.Trim();
            t_book_site.BookListUrl = txt_book_list.Text.Trim();
            int intTemp=0;
            if(!int.TryParse(txt_book_name_index.Text.Trim(),out intTemp))
                intTemp=0;
            t_book_site.BookNameIndex = intTemp;
            if(!int.TryParse(txt_chapter_content_index.Text.Trim(),out intTemp))
                intTemp=0;
            t_book_site.ChapterContentIndex = intTemp;
            t_book_site.ChapterContentReg = txt_chapter_content_reg.Text.Trim();
            t_book_site.ChapterListReg = txt_chapter_list_reg.Text.Trim();
            if(!int.TryParse(txt_chapter_list_index.Text.Trim(),out intTemp))
                intTemp=0;
            t_book_site.ChapterListUrlIndex = intTemp;
            if(!int.TryParse(txt_chapter_name_index.Text.Trim(),out intTemp))
                intTemp=0;
            t_book_site.ChapterNameIndex = intTemp;
            if(!int.TryParse(txt_chapter_url_index.Text.Trim(),out intTemp))
                intTemp=0;
            t_book_site.ChapterUrlIndex = intTemp;
            t_book_site.ForbidWords = txt_forbidwords.Text.Trim();
            t_book_site.SiteDomain = txt_site_domain.Text.Trim();
            t_book_site.SiteEnconding = txt_site_enconding.Text.Trim();
            t_book_site.SiteName = txt_site_name.Text.Trim();
            int t_type = 1;
            if (m_data_row != null)
            {
                if (!int.TryParse(m_data_row["siteId"].ToString(), out intTemp))
                    intTemp = 0;
                t_book_site.SiteId = intTemp;

                t_type = 2;
            }
            DBManager t_db_mgr=new DBManager();
            try
            {
                int t_ret = 1; //t_db_mgr.UpdateSmallBookSite(t_book_site, t_type);
                if (t_ret > 0)
                {
                    MessageBox.Show("操作成功", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    this.DialogResult = DialogResult.OK;
                    this.Close();
                }
                else
                {
                    MessageBox.Show("操作失败,请查看异常日志", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
                }
            }
            catch (Exception ex)
            {
                LogHelper.Error("添加站点信息失败" + ex.ToString());
                MessageBox.Show("操作失败,请查看异常日志", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
            }
        }

        /// <summary>
        /// 窗体加载
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void FrmSite_Load(object sender, EventArgs e)
        {
            if (m_data_row != null)
            {
                txt_book_list.Text = m_data_row["bookListUrl"].ToString();
                txt_book_list_reg.Text = m_data_row["bookListReg"].ToString();
                txt_book_name_index.Text = m_data_row["bookNameIndex"].ToString();
                txt_chapter_content_index.Text = m_data_row["chapterContentIndex"].ToString();
                txt_chapter_content_reg.Text = m_data_row["chapterContentReg"].ToString();
                txt_chapter_list_index.Text = m_data_row["chapterListUrlIndex"].ToString();
                txt_chapter_list_reg.Text = m_data_row["chapterListReg"].ToString();
                txt_chapter_name_index.Text = m_data_row["chapterNameIndex"].ToString();
                txt_chapter_url_index.Text = m_data_row["chapterUrlIndex"].ToString();
                txt_forbidwords.Text = m_data_row["forbidWords"].ToString();
                txt_site_domain.Text = m_data_row["siteDomain"].ToString();
                txt_site_enconding.Text = m_data_row["siteEnconding"].ToString();
                txt_site_name.Text = m_data_row["siteName"].ToString();
            }
        }
    }
}
